package com.lin.controller;

import com.sun.org.glassfish.gmbal.ParameterNames;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName HelloController
 * @Description
 * @Author lin
 * @Date 2021/12/5 上午1:22
 * @Version V1.0
 */
@Controller
public class HelloController {
    @RequestMapping("/hello")
    public String hello(Model mode){
        mode.addAttribute("msg","hello,spring-mvc");
        return "hello.jsp";
    }

    @RequestMapping(value = "/forward",method = RequestMethod.GET)
    public String zhuanfa(Model mode){
        mode.addAttribute("msg","这是转发的请求");
        return "forward.jsp";
    }

    @RequestMapping(value = "/redirect",method = RequestMethod.GET)
    public String chongdingiang(Model mode){
        mode.addAttribute("msg","这是重定向的请求");
        return "redirect.jsp";
    }

    @GetMapping("encoding/test")
    public ModelAndView encodingT1(String text){
        System.out.println(text);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",text);
        modelAndView.setViewName("hello.jsp");
        return modelAndView;
    }

    @PostMapping("encoding/test")
    public ModelAndView encodingT2(String text){
        System.out.println(text);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",text);
        modelAndView.setViewName("hello.jsp");
        return modelAndView;
    }


}
